//
//  DHCAnimation.m
//  DeepBreathing
//
//  Created by rimi on 15/12/22.
//  Copyright © 2015年 rimi. All rights reserved.
//

#import "DHCAnimation.h"

@interface DHCAnimation ()

@property (nonatomic, strong) CABasicAnimation * animation;
@property (nonatomic, copy) void (^completionBlock)(BOOL finished);


@end

@implementation DHCAnimation

+ (instancetype)animationWithKeyPath:(NSString *)keyPath duration:(NSTimeInterval)duration fromValue:(id)fromValue completionBlock:(void (^)(BOOL flag))completion
{
    DHCAnimation * animation = [[DHCAnimation alloc] init];
    animation.completionBlock = completion;
    
    animation.animation = ({
        
        CABasicAnimation * anim = [CABasicAnimation animation];
        anim.duration = duration;
        anim.keyPath = keyPath;
        anim.fromValue = fromValue;
        anim.delegate = animation;
        anim;
        
    });
    
    return animation;
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    if (self.completionBlock) {
        self.completionBlock(flag);
    }
}


@end
